<?php
	session_start();	
?>

<?php
	if( $_SESSION["admin"] != "" )
	{
?>
<a href="index.php?com=coupon"><b>List coupon</b></a> | <a href="index.php?com=coupon&func=add"><b>Add coupon</b></a>
<?php
	include_once("process/coupon.php");	
	$coupon = new coupon();
	
	if( $_GET["com"] == "coupon" && $_GET["func"] == "update" && isset($_GET["id"]))
	{
		$row = $coupon->GetOneCoupon($_GET['id']);	
	}elseif( isset($_POST['btnUpdate']) )
	{	
			$code = stripcslashes($_POST["CouponCode"]);
    		$title=stripcslashes($_POST["CouponTitle"]);
    		$type=stripcslashes($_POST["CouponType"]);
            $note=stripcslashes($_POST["Note"]);
            $value=stripcslashes($_POST["Value"]);
            $id = stripcslashes($_POST["CouponID"]);
			$coupon->UpdateCoupon($code, $title, $type, $note, $value, $id);
			echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=coupon" />';
	}
	else
	{
		echo '<meta http-equiv="Refresh" content="0;URL=index.php?com=coupon" />';
	}	
	
?>
<form action="index.php?com=coupon&func=update" method="post" id="contactform">
	<table width="630px" style="font-weight:bold; font-size:10pt;" border="0">
		<tr>
			<td align="center" colspan="4" height="50"><b style="font-size:12pt; color:Blue;">Update coupon</b></td>
		</tr>
		<tr height="26">
			<td align="right" width="120px">Coupon Code :&nbsp;&nbsp;
				<input type="hidden" class="validate[required]" name="CouponID" id="CouponID" value="<?php echo $row['CouponID'] ?>" />
			</td>
			<td width="140px"><input type="text" name="CouponCode" id="CouponCode" value="<?php echo $row['CouponCode']; ?>" style="width: 120px;" /><font style="color: red;"> *</font>
				<input type="hidden" name="CouponID" id="CouponID" value="<?php echo $row['CouponID'] ?>" />
			</td>
        </tr>
        <tr>
			<td align="right" width="120px">Coupon Title :&nbsp;&nbsp;</td>
			<td><input type="text" class="validate[required]" name="CouponTitle" id="CouponTitle" value="<?php echo $row['CouponTitle']; ?>" style="width: 120px;" /><font style="color: red;"> *</font></td>
		</tr>  	    
        <tr>
			<td align="right" width="120px">Coupon Type :&nbsp;&nbsp;</td>
			<td><input type="text" class="validate[required]" name="CouponType" id="CouponType" value="<?php echo $row['CouponType']; ?>" style="width: 120px;" /><font style="color: red;"> *</font></td>
		</tr> 
        <tr>
			<td align="right" width="120px">Note :&nbsp;&nbsp;</td>
			<td><input type="text" name="Note" id="Note" value="<?php echo $row['Note']; ?>" style="width: 120px;" /><font style="color: red;"> *</font></td>
		</tr>  	    
        <tr>
			<td align="right" width="120px">Value :&nbsp;&nbsp;</td>
			<td><input type="text" name="Value" id="Value" value="<?php echo $row['Value']; ?>" style="width: 120px;" /><font style="color: red;"> *</font></td>
		</tr>
		<tr>
			<td></td>
			<td colspan="3" height="40">
				<input type="submit" name="btnUpdate" id="btnUpdate" value="Update" />
				<input type="reset" value="Reset" />
			</td>
		</tr>
    </table>
</form><br><br>
<i>Please fill in these fields (<font style="color: red;">*</font>)</i>
<?php
    }
   else
	{
		echo "<meta http-equiv='refresh' content='0; url=login.php' />";
	}
?>